// pages/new-pages/my-product/my-product.js
const app = getApp()
import Toast from '../../../component/toast/toast';
Page({

    /**
     * 页面的初始数据
     */
    data: {
        listData:null
    },
    getMyWorks() {
        let that = this;
        wx.showLoading({
            title: '加载中...',
            mask: true
        })
        wx.request({
            url: app.globalData.serverAddress.getMyWorks,
            data: {
                pageSize: 20,
                pageIndex: 0,
                currentUserInfoId: app.userInfo.Id,
                fileType: 0
            },
            header: {
                'Authorization': "Bearer " + app.globalData.token
            },
            method: 'GET',
            success: function (res) {
                console.log(res);
                if (res.statusCode == 200 && res.data.CodeStatus == 20000) {
                    console.log(res.data.BodyContent);
                    let list = res.data.BodyContent.List;
                    that.setData({
                        listData:list
                    })
                } else if (res.statusCode == 200 && res.data.CodeStatus == 40005) {
                    that.setData({
                        hasMore: false
                    });
                }
                // Toast(res.data.Message);
            },
            fail: function (res) {
                console.log("fail" + JSON.stringify(res));
                Toast(res.data.Message);
            },
            complete: function (res) {
                wx.hideLoading();
            },
        })
    },
    selectGirdItem(e){
        let index = e.currentTarget.dataset.index;
        let fileUrl = this.data.listData[index].FileUrl;
        wx.previewImage({
            urls: [fileUrl]
        })
    },
    // 上传作品
    clickProduct(){
        this.getResumeInfoById();
    },
    getResumeInfoById() {
        wx.showLoading({
            title: '加载中...',
            mask: true
        });
        let that = this;
        wx.request({
            url: app.globalData.serverAddress.getResumeInfoById,
            data: {
                userInfoId: app.userInfo.Id
            },
            header: {
                'Authorization': "Bearer " + app.globalData.token
            },
            method: 'GET',
            success: function (res) {
                console.log('getResumeInfoById response', res);
                if (res.statusCode == 200) {
                    if (res.data.CodeStatus == 20000) {
                        let data = res.data.BodyContent;
                        wx.navigateTo({
                            url: '/pages/new-pages/scan-hint/scan-hint?resumeId=' + data.Id
                        })
                    }
                } else {
                    // Toast(res.data.Message);
                }
            },
            fail: function (res) {
                console.log("getResumeInfoById fail", res)
            },
            complete: function (res) {
                wx.hideLoading();
            },
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.getMyWorks()
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})